package gcosc.fun.hly.fastsso.controller;

import gcosc.fun.hly.fastsso.annotation.Ignore;
import gcosc.fun.hly.fastsso.domain.Bo.LoginBo;
import gcosc.fun.hly.fastsso.domain.SsoUser;
import gcosc.fun.hly.fastsso.result.Result;
import gcosc.fun.hly.fastsso.service.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@RequestMapping("/sso/auth")
public class AuthController {

    private final AuthService authService;

    @Ignore
    @GetMapping("/is")
    public Result isLogin(@RequestHeader("Authorization") String token){
        return Result.ok(authService.isLogin(token));
    }

    @Ignore
    @PostMapping("/login")
    public Result login(@RequestBody LoginBo loginBo){
        return Result.ok(authService.login(loginBo));
    }

    @Ignore
    @PostMapping("/register")
    public Result register(@RequestBody SsoUser ssoUser){
        return Result.ok(authService.register(ssoUser));
    }

    @Ignore
    @GetMapping("/getInfo")
    public Result getInfo(@RequestHeader("Authorization") String token){
        return Result.ok(authService.getLoginUserByToken(token));
    }

    @Ignore
    @PostMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token){
        return Result.ok(authService.logout(token));
    }

}
